<?php
namespace Home\Controller;
use Think\Controller;
class CategoryController extends Controller
{
	//分类页
	public function index ()
	{
		//var_dump($_POST);
		if (!empty($_POST)) {
			//var_dump($_POST); exit;
			$li = $_POST['name'];
			
			//$da['name'] = array('like','%'.$li.'%'); 
			//var_dump($data);exit;
			/*$count = M('movie')->where('face'.$data)->count();
			$page = new \Think\Page($count,5);
			$show = $page->show();*/
			/*$li = M('movie')->where($data)->limit($page->firstRow.','.$page->listRows)->select();*/
			$count = M('movie')->where('face=1 and name like"%'.$li.'%"')->join('lamp_img on lamp_movie.id=lamp_img.mid')->count();
			//var_dump($count);exit;
			$page = new \Think\Page($count,6);
			$data1 = M ('movie')->field ('lamp_movie.id,icon,cid,name,language,duration,director')->where('face=1 and name like"%'.$li.'%"')->join('lamp_img on lamp_movie.id=lamp_img.mid')->limit($page->firstRow.','.$page->listRows)->select();
			//var_dump($data1); exit; 
		} else {
		if(I('get.cid/d')) {
			$cid = I('get.cid/d');
			//var_dump($cid);
			$count = M('movie')->where('face=1 and cid like "%'.$cid.'%"')->join('lamp_img on lamp_movie.id=lamp_img.mid')->count();
			//var_dump($count);exit;
			$page = new \Think\Page($count,6);
			$data1 = M ('movie')->field ('lamp_movie.id,icon,cid,name,language,duration,director')->where ('face=1 and cid like "%'.$cid.'%"')->join('lamp_img on lamp_movie.id=lamp_img.mid')->limit($page->firstRow.','.$page->listRows)->select();
			//var_dump($data1);exit;
		} else {
			$count = M('movie')->where('face=1')->join('lamp_img on lamp_movie.id=lamp_img.mid')->count();
			//var_dump($count);exit;
			$page = new \Think\Page($count,6);
			$data1 = M ('movie')->field ('lamp_movie.id,icon,cid,name,language,duration,director')->where('face=1')->join('lamp_img on lamp_movie.id=lamp_img.mid')->limit($page->firstRow.','.$page->listRows)->select();
			//var_dump($data1); 
		}
		} 
		$page->setConfig('prev','上一页');
		$page->setConfig('next','下一页');
		$id = I ('get.td/d');
		//var_dump($id); exit;
		$da = M('category')->field('id,name')->where('pid=0')->select();
		//var_dump($da);exit;
		//var_dump($id);exit;
		$data = M ('category')->where ('display=0 and pid='.$id)->select ();
		// var_dump($da);
		$show = $page->show();

		if (!$data1) {
			$this->assign ('row','暂无搜索的内容...');
		}
		
		//echo M('movie')->getLastSql();
		//var_dump($data1);exit;
		//$data2 = M('movie')->field('cid')->select();
		//var_dump($data2); exit;
		/*$data = M ('category')->where ('display=0 and pid='.$id)->select ();*/
		//var_dump($data); exit;
		//var_dump($data);exit;
		$i1 = 5;
		$i2 = 6;
		$i3 = 7;
		$i4 = 8;
		$i5 = 9;
		$i6 = 10;
		$i7 = 11;
		$i8 = 12;
		$i9 = 13;
		$i10 = 14;
		$i11 = 15;
		$i12 = 16;
		$i13 = 19;
		$i14 = 20;
		$this->assign ('i1',$i1);
		$this->assign ('i2',$i2);
		$this->assign ('i3',$i3);
		$this->assign ('i4',$i4);
		$this->assign ('i5',$i5);
		$this->assign ('i6',$i6);
		$this->assign ('i7',$i7);
		$this->assign ('i8',$i8);
		$this->assign ('i9',$i9);
		$this->assign ('i10',$i10);
		$this->assign ('i11',$i11);
		$this->assign ('i12',$i12);
		$this->assign ('i13',$i13);
		$this->assign ('i14',$i14);
		$this->assign ('list1',$data1);
		$this->assign ('list',$data);
		$this->assign ('list2',$data2);
		$this->assign ('id',$id);
		$this->assign ('page',$show);
		$this->assign ('da',$da);
		$this->display ();
	}
}